package controllers

import (
	beego "github.com/beego/beego/v2/server/web"
	"strings"
)

type baseController struct {
	beego.Controller
}

//获取用户IP地址
func (p *baseController) getClientIp() string {
	s := strings.Split(p.Ctx.Request.RemoteAddr, ":")
	return s[0]
}

type ReturnMsg struct {
	Code int
	Msg  string
	Data interface{}
}

func (this *baseController) SuccessJson(data interface{}) {

	res := ReturnMsg{
		200, "success", data,
	}
	this.Data["json"] = res
	this.ServeJSON() //对json进行序列化输出
	this.StopRun()
}

func (this *baseController) ErrorJson(code int, msg string, data interface{}) {

	res := ReturnMsg{
		code, msg, data,
	}

	this.Data["json"] = res
	this.ServeJSON() //对json进行序列化输出
	this.StopRun()
}

